<?php
include_once('./common.php');

if(is_file('data/action_install.lock')) showmessage('data/action_install.lock exists', 'space.php', 3);

$charset = str_replace('-', '', $_SC['charset']);
$extend = $_SGLOBAL['db']->version() > '4.1' ? " DEFAULT CHARSET={$charset} " : "";

$sql[] = "
CREATE TABLE IF NOT EXISTS `uchome_app_action` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `uid` int(10) unsigned NOT NULL default '0',
  `username` varchar(20) NOT NULL default '',
  `subject` varchar(150) NOT NULL default '',
  `type` tinyint(1) unsigned NOT NULL default '0',
  `type_company` varchar(64) NOT NULL default '',
  `p` varchar(20) default '',
  `c` varchar(20) NOT NULL default '',
  `area` varchar(250) NOT NULL default '',
  `person_num` int(10) unsigned NOT NULL default '0',
  `description` text NOT NULL,
  `eventtype` varchar(50) NOT NULL default '',
  `start_time` int(10) unsigned NOT NULL default '0',
  `end_time` int(10) unsigned NOT NULL default '0',
  `price_type` varchar(50) NOT NULL default '',
  `price_description` varchar(100) NOT NULL default '',
  `collect_area` varchar(250) NOT NULL default '',
  `contact` varchar(100) default '',
  `collect_type` tinyint(1) unsigned NOT NULL default '0',
  `privite` tinyint(1) unsigned NOT NULL default '0',
  `picture` varchar(200) NOT NULL default '',
  `join_num` int(10) unsigned NOT NULL default '0',
  `interest_num` int(11) unsigned NOT NULL default '0',
  `announce` text,
  `dateline` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `uid` (`uid`),
  KEY `p` (`p`,`c`),
  KEY `start_time` (`start_time`,`end_time`)
) ENGINE=MyISAM  {$extend};";

$sql[] = "CREATE TABLE IF NOT EXISTS `uchome_app_action_album` (
  `pid` int(10) unsigned NOT NULL auto_increment,
  `id` int(10) unsigned NOT NULL default '0',
  `title` varchar(250) default '',
  `img` varchar(250) default '',
  `ext` varchar(5) default '',
  `uid` int(10) unsigned NOT NULL default '0',
  `username` varchar(20) NOT NULL default '',
  `dateline` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`pid`),
  KEY `id` (`id`)
) ENGINE=MyISAM   {$extend};";

$sql[] = "CREATE TABLE IF NOT EXISTS `uchome_app_action_invite` (
  `id` int(10) unsigned NOT NULL default '0',
  `uid` int(10) unsigned NOT NULL default '0',
  `hash` int(10) default '0',
  UNIQUE KEY `id` (`id`,`uid`)
) ENGINE=MyISAM {$extend};";

$sql[] = "CREATE TABLE IF NOT EXISTS `uchome_app_action_invite_site` (
  `oid` int(10) unsigned NOT NULL auto_increment,
  `id` int(10) unsigned default '0',
  `email` varchar(64) NOT NULL default '',
  `code` int(10) unsigned NOT NULL default '0',
  `status` tinyint(1) unsigned NOT NULL default '0',
  PRIMARY KEY  (`oid`),
  KEY `id` (`id`,`email`)
) ENGINE=MyISAM  {$extend};";
$sql[] = "CREATE TABLE IF NOT EXISTS `uchome_app_action_join` (
  `id` int(10) unsigned NOT NULL default '0',
  `uid` int(10) unsigned NOT NULL default '0',
  `username` varchar(20) NOT NULL default '',
  `type` enum('join','interest') NOT NULL default 'join',
  `status` tinyint(1) unsigned NOT NULL default '0',
  `is_pass` tinyint(1) unsigned NOT NULL default '0',
  UNIQUE KEY `uid` (`uid`,`id`),
  KEY `id` (`id`,`type`,`is_pass`)
) ENGINE=MyISAM {$extend};";
$sql[] = "CREATE TABLE IF NOT EXISTS `uchome_app_action_reply` (
  `pid` int(10) unsigned NOT NULL auto_increment,
  `id` int(10) unsigned NOT NULL default '0',
  `parentid` int(10) unsigned NOT NULL default '0',
  `dpath` tinyint(4) unsigned NOT NULL default '0',
  `uid` int(10) unsigned NOT NULL default '0',
  `username` varchar(20) NOT NULL default '',
  `message` text NOT NULL,
  `dateline` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`pid`),
  KEY `id` (`id`)
) ENGINE=MyISAM {$extend};";

foreach($sql as $val){
	$_SC['tablepre'] != 'uchome_' && $val = str_replace("`uchome_", '`'. $_SC['tablepre'], $val);
	$val = siconv($val, $_SC['charset'], 'utf-8');
	$_SGLOBAL['db']->query($val);
}

swritefile('data/action_install.lock', $_SERVER['REQUEST_TIME']);
showmessage('success', 'action.php', 1);
?>